/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pluginTable;

import java.io.Serializable;
import javax.swing.table.AbstractTableModel;

/**
 * cette est le modele de la table. savegarde les données saisi
 * 
 *
 * @author mazid
 */
public class ModelTable extends AbstractTableModel implements Serializable{
    private int maxLine = 100;
    private int maxColone = 50;
    private Object[][] donnees; 
    
    public ModelTable(){
        donnees = new Object[maxLine][maxLine];
    }
    public Object[][] getDonnees() {
        return donnees;
    }
    
    // pour reunitialiser la table pour une nouvelle table vide
   
    @Override
    public int getRowCount() {
        return maxLine;
    }

    @Override
    public int getColumnCount() {
        return maxColone;
    }
    @Override
    public String getColumnName (int columnIndex) {
        return getColumnNamePerforme (columnIndex);
    }
    // renvoie le nom des colonnes a partir de columIndex +1
    private static String getColumnNamePerforme(int columnIndex) {
        if (columnIndex == 0) {
            return "";
        }
        if (columnIndex <= 26) {
            return Character.toString((char)(columnIndex+64));
        }
        return Character.toString((char)(64+(columnIndex/26)))+((char)(64+(columnIndex%26)));
    }
    public static String getCellName (int rowIndex, int columnIndex) {
        return getColumnNamePerforme (columnIndex)+Integer.toString(rowIndex+1);
    }
    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        if(columnIndex ==0){
            return false;
        }
        return true; //Toutes les autres cellules éditables
    }
    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        donnees[rowIndex][columnIndex]=aValue;
        fireTableCellUpdated(rowIndex, columnIndex);
        
    }

    @Override
    public Object getValueAt(int rowIndex, int columIndex) {
        if(columIndex==0){
            return Integer.toString(rowIndex+1);
        }
        return donnees[rowIndex][columIndex];
    }

    
}
